<%namespace name="admin_include" file="/admin/base/include.html" />
<%inherit file="/front/base/normalbase.html"/>
<%def name="center()">
${admin_include.validationEngine()}
<style>
.form-horizontal .control-group {
    margin-bottom:5px;
}
</style>
<div class="row">
    <h3 class="lit page-header no-margin" style="margin-bottom:10px;">填写核对订单信息</h3>
    <form class="form-horizontal" id="dataform" action="${request.url}" method="post" enctype="multipart/form-data" style="background-color:#EFF5F8;padding:15px;">
        <fieldset>
            <h4><strong>收件人信息</strong></h4>
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td colspan="2">
                        <div class="control-group">
                        <label class="control-label control-label-small">收件人</label>
                            <div class="controls controls-small">
                                <input name="receiver" type="text" value="${user and user.realname or ''}" class="input-large validate[required, maxSize[5]]"/>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <div class="control-group">
                        <label class="control-label control-label-small">地址</label>
                            <div class="controls controls-small">
                                <input name="address" type="text" value="${user and user.address or ''}" class="input-xlarge validate[required, maxSize[200]]"/>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="control-group">
                        <label class="control-label control-label-small">手机</label>
                            <div class="controls controls-small">
                                <input name="tel" type="text" value="${user and user.tel or ''}" class="input-large validate[required, custom[integer]]"/>
                            </div>
                        </div>
                    </td>
                    <td>
                        <div class="control-group">
                        <label class="control-label control-label-small">邮箱</label>
                            <div class="controls controls-small">
                                <input name="email" type="text" value="${user and user.email or ''}" class="input-large validate[custom[email]]"/>
                            </div>
                        </div>
                    </td>
                </tr>
            </table>
            <h4><strong>商品清单</strong></h4>
            <table class="table table-bordered table-striped" style="table-layout:fixed;">
                <thead class="typ">
                    <tr>
                        <th width="90" style="text-align:center">商品</th>
                        <th width="10" style="text-align:center">数量</th>
                        <th width="15" style="text-align:center">单价</th>
                        <th width="20" style="text-align:center">小计</th>
                    </tr>
                </thead>
                <tbody>
                    <%
                    sum_price = 0
                    %>
                    %if request.session.has_key('shoppingcart'):
                    %for detail in request.session['shoppingcart']:
                    <%
                    sum_price = sum_price + detail.number*detail.sellprice
                    %>
                    <tr>
                        <td>
                            <p>${detail.name}</p>
                        </td>
                        <td style="text-align:center;">
                            <p>${detail.number}</p>
                        </td>
                        <td style="text-align:center;">
                            <p class="no-margin">¥${detail.sellprice}</p>
                        </td>
                        <td style="text-align:center;">
                            <p class="no-margin">¥${detail.number * detail.sellprice}</p>
                        </td>
                    </tr>
                    %endfor
                    <tr>
                        <td colspan="4">
                            <p style="padding-left:60px;" class="pull-right">总计:<span id="originSumPrice" class="label label-success" style="font-size:16px;margin-left:20px;">¥${sum_price}</span></p>
                        </td>
                    </tr>
                    %endif
                </tbody>
            </table>
            %if coupons and len(coupons)>0:
            <p><a href="#" id="usecoupon"><i id="addcouponicon" class="icon-minus-sign"></i>使用优惠券</a></p>
            <div id="couponlist" class="controls" style="margin:0;">
                %for coupon in coupons:
                <label class="radio">
                    <input id="couponradio${coupon.id}" type="radio" name="coupon" value="${coupon.id}"/>
                    <input id="couponMinus${coupon.id}" type="hidden" value="${coupon.rule.split('/')[0]}"/>
                    ${coupon.name} 
                </label>
                %endfor
            </div>
            <a id="coupon_yes" class="btn btn-small" href="">确认</a>
            <a id="coupon_no" class="btn btn-small" href="">暂不需要</a>
            %endif

            <p class="atv" style="height:30px;"><strong class="pull-right">需要支付费用：¥<span id="sumPrice">${sum_price}</span></strong></p>

            %if request.session.has_key('shoppingcart') and len(request.session['shoppingcart']) > 0:
            <p><button class="btn btn-primary btn-large" style="margin-left:750px;">&nbsp;&nbsp;&nbsp;提交订单&nbsp;&nbsp;&nbsp;</button></p>
            %endif
        </fieldset>
    </form>
</div>
</%def>


<%def name="script()">
<script type="text/javascript">
$(document).ready(function(){
    $('#dataform').validationEngine();
    $('#coupon_no').click(function(){
        $("input[id^='couponradio']").removeAttr('checked');
        var newprice = parseInt($('#originSumPrice').text().replace('¥',''));
        $('#sumPrice').text(newprice);
        return false;
    });
    $('#coupon_yes').click(function(){
        //check select at least one coupon
       var checkedValue = $("input:radio[name='coupon']:checked").val();
       if(checkedValue == null){
        alert('请选择一个优惠券.');
        return false;
       }

      //use the coupon 
      var checkedId = $("input:radio[name='coupon']:checked").attr('id').replace('couponradio','');
      var minus = $('#couponMinus' + checkedId).val();
      var newprice = parseInt($('#originSumPrice').text().replace('¥','')) - parseInt(minus);
      $('#sumPrice').text(newprice);

       return false;
    })
    $('#usecoupon').click(function(){
        return false;
    });
});
</script>
</%def>
